<?php
    use User\Model\MemberModel;
?>
<!-- page heading start-->
<div class="page-heading">
    <h3>
        会员列表
    </h3>

</div>
<!-- page heading end-->
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <header class="panel-heading">
                <a class="btn btn-default" href="/User/Member/memberAdd">增加</a>
                <a class="btn btn-default" href="/User/Member/index">会员列表</a>
                <a class="btn btn-default" href="/User/Member/memberClass">层级管理</a>
                <a class="btn btn-default" href="/User/Member/service">会员服务</a>
                <a class="btn btn-default" href="/User/Member/property">会员扩展信息</a>
                <a class="btn btn-default" href="/User/Member/item">服务项目</a>
            </header>
            <div class="panel-body">
                <table class="table table-hover general-table table-bordered">
                    <thead>
                    <tr>
                        <th width="12%">会员名称</th>
                        <th width="12%">会员类型</th>
                        <th width="12%">地址</th>
                        <th width="10%">电话</th>
                        <th width="10%">渠道</th>
                        <th width="10%">创建时间</th>
                        <th width="10%">状态</th>
                        <th width="10%">最近登陆时间</th>
                        <!--<th width="10%">扩展属性</th>-->
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach($list as $val){?>
                    <tr>
                        <td>
                            <span>
                                <?php echo $val['name'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo isset($member_class[$val['class_id']]) ? $member_class[$val['class_id']] : "";?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php
                                    $address = '';
                                    if(isset($region[$val['province']])){
                                        $address .= $region[$val['province']];
                                    }
                                    if(isset($region[$val['city']])){
                                        $address .= $region[$val['city']];
                                    }
                                    if(isset($region[$val['district']])){
                                        $address .= $region[$val['district']];
                                    }
                                    $address .= $val['address'];
                                    echo $address;
                                ?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo $val['phone'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo MemberModel::get_channel($val['channel']);?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo $val['added_time'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo MemberModel::get_status($val['status']);?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo $val['last_login_date'];?>
                            </span>
                        </td>
                        <!--<td>
                            <span>
                                <?php echo $val['ext'];?>
                            </span>
                        </td>-->
                        <td>
                            <a class="btn btn-success"
                               href="<?php echo '/User/Member/memberUpdate?type=update&memberId=' . $val['member_id'];?>">编辑</a>
                            <a class="btn btn-default" href="#"
                               onclick="<?php echo 'return delete_data(' . $val['member_id'] .')';?>">删除</a>
                            <?php
                                if($val['status'] == MemberModel::STATUS_PENDING){
                            ?>
                            <br><br>
                            <a class="btn btn-info" href="#"
                               onclick="<?php echo 'return active_data(' . $val['member_id'] .')';?>">激活</a>
                            <?php }?>
                        </td>
                    </tr>
                    <?php }?>

                    </tbody>
                </table>
                <div class="pages">
                    {$page}
                </div>
            </div>
        </section>
    </div>
</div>
<script>
    function delete_data(id){
        $.ajax({
            data:{memberId:id},
            dataType:'json',
            url:'/User/Member/memberDelete',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
    function active_data(id){
        $.ajax({
            data:{memberId:id},
            dataType:'json',
            url:'/User/Member/memberActive',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
</script>